#include "cpu/exec.h"
#include "memory/mmu.h"

void raise_intr(uint8_t NO, vaddr_t ret_addr)
{
  /* TODO: Trigger an interrupt/exception with ``NO''.
   * That is, use ``NO'' to index the IDT.
   */

  t3 = cpu.cs;
  rtl_push(&cpu.eflag);
  cpu.eflags.IF=0;
  rtl_push(&t3);
  rtl_push(&ret_addr);
  vaddr_t base_addr = cpu.idtr.base;
  vaddr_t desc_addr = base_addr + NO * 8;
  vaddr_t high, low;
  high = vaddr_read(desc_addr + 4, 4) & 0xffff0000;
  low = vaddr_read(desc_addr, 4) & 0xffff;
  decoding.is_jmp = true;
  decoding.jmp_eip = high | low;
}

void dev_raise_intr()
{
  cpu.INTR=true;
}
